
// Definition for a binary tree node.
struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
#include <queue>
#include <climits>
using namespace std;
class Solution
{
public:
    int findBottomLeftValue(TreeNode *root)
    {
        if (!root)
            return 0;
        queue<TreeNode *> que;
        que.push(root);
        int res = INT_MIN;
        // 层序遍历
        while (!que.empty())
        {
            int level_num = que.size();
            if (level_num)
                res = que.front()->val;
            while (level_num--)
            {
                TreeNode *cur_node = que.front();
                que.pop();
                if (cur_node->left)
                    que.push(cur_node->left);
                if (cur_node->right)
                    que.push(cur_node->right);
            }
        }
        return res;
    }
};